﻿using System;
using System.Collections.Generic;
using System.Text;
using Wolfut.MirageEE.Interface.Common;
using Wolfut.MirageEE.Domain.Common;
using Castle.Services.Transaction;
using MiragePWF.NH.Logging;
using Wolfut.MirageEE.Kernal.Common;
using MiragePWF.NH.Repositories;
using NHibernate.Criterion;

namespace Wolfut.MirageEE.Server.Server.Common
{
    [Transactional]
    [AutoLogging]
    public class EmployeesService : BusinessServiceBase, IEmployeesService
    {
        private readonly IRepository<Employee> employeeRepository;

        public EmployeesService(IRepository<Employee> employeeRepository)
        {
            this.employeeRepository = employeeRepository;
        }

        #region IEmployeesService 成员
        [Transaction(TransactionMode.Requires)]
        public Employee AddOrUpdateEmployee(Employee employee)
        {
            employeeRepository.Save(employee);
            return employee;
        }

        public IList<Employee> GetEmployees(bool isDeleted)
        {
            DetachedCriteria criteria = DetachedCriteria.For(typeof(Employee));
            //if (!string.IsNullOrEmpty(currencyCode))
            //{
            //    criteria.Add(Expression.Eq("CurrencyCode", currencyCode));

            //}
            //if (!string.IsNullOrEmpty(currencyName))
            //{
            //    criteria.Add(Expression.Like("currencyName", currencyCode, MatchMode.Anywhere));

            //}
            criteria.Add(Expression.Eq("IsDeleted", isDeleted));
            return employeeRepository.FindAll(criteria);
            //return null;
        }

        #endregion
    }
}
